use strict;
use warnings;

my $in = "OneKg.pops";
my $ped = "SchistoCandGenes.1kg.h3a.fam";
if($ARGV[0]){
	$ped = $ARGV[0];
}
my $pe =substr($ped,0,-4);
my %id;
open(IN, "<$in") || die "$in $!\n";

<IN>;
while(<IN>){
	chomp();
	my @dat = split(/\s+/);
	$id{$dat[0]} = $dat[1] . substr($dat[0],3);
}
close(IN);

my $lineNo = 0;
my $new =  "$pe.rehead." . substr($ped,-3);
open(IN, "<$ped") || die  "$ped $!\n";
open(OUT, ">$new") || die "$new $!\n";
while(<IN>){
	my @data = split(/\s+/);
	print " $data[0];  $data[1]\n";
	if($id{$data[0]}){
		$data[0] = $id{$data[0]};
		$data[1] = $id{$data[1]};
	}
	print " $data[0];  $data[1]\n";
	print(OUT  join("\t", @data) . "\n");

}
close(IN);
close(OUT);
